using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;

namespace MBMC.Dialogs.NewMod
{
    public partial class Step1 : Form
    {
        public Step1()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            label5.Text = @"\Marble Blast " + textBox3.Text;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                if (textBox2.Text != "")
                {
                    if (textBox3.Text != "")
                    {
                        //copy directory
                        label6.Enabled = true;
                        progressBar1.Value = 2;
                        textBox1.Enabled = false;
                        button1.Enabled = false;
                        button2.Enabled = false;
                        button3.Enabled = false;
                        button4.Enabled = false;
                        textBox2.Enabled = false;
                        textBox3.Enabled = false;
                        CopyDirectory(textBox2.Text, textBox3.Text + "/" + textBox1.Text, true);
                        progressBar1.Value = 100;
                        button3.Enabled = true;
                    }
                }
            }
        }

        public bool CopyDirectory(string SourcePath, string DestinationPath, bool overwriteexisting)
        {
            bool ret = false;
            //try
            //{
                SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";
                DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";
                
                if (Directory.Exists(SourcePath))
                {
                    if (Directory.Exists(DestinationPath) == false)
                        Directory.CreateDirectory(DestinationPath);

                    foreach (string fls in Directory.GetFiles(SourcePath))
                    {
                        FileInfo flinfo = new FileInfo(fls);
                        flinfo.CopyTo(DestinationPath + flinfo.Name, overwriteexisting);
                    }
                    foreach (string drs in Directory.GetDirectories(SourcePath))
                    {
                        DirectoryInfo drinfo = new DirectoryInfo(drs);
                        if (CopyDirectory(drs, DestinationPath + drinfo.Name, overwriteexisting) == false)
                            ret = false;
                    }
                }
               ret = true;
                
            //}
            //catch (Exception ex)
            //{
            //    ret = false;
            //}
            return ret;
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Step1_Load(object sender, EventArgs e)
        {
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.ShowDialog();
            textBox1.Text = folderBrowserDialog1.SelectedPath;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            folderBrowserDialog2.ShowDialog();
        }

        private void folderBrowserDialog1_HelpRequest(object sender, EventArgs e)
        {
            textBox1.Text = folderBrowserDialog1.SelectedPath;
            textBox2.Text = folderBrowserDialog2.SelectedPath;
        }

        private void folderBrowserDialog2_HelpRequest(object sender, EventArgs e)
        {
            textBox2.Text = folderBrowserDialog2.SelectedPath;
        }
    }
}